﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PCBase.UIControls;

namespace VisionCore
{
    public class PRM_Mode_Rec
    {
        [DisplayName("已倒膜上料模式"), Description("倒膜平台；挑拣平台")]
        [TypeConverter(typeof(LoadMode))]
        public string LoadMode { get; set; } = "倒膜平台";


        [DisplayName("载出平台落Tray模式"), Description("True:启用落tray吸真空，false:关闭落tray吸真空")]
        public bool ULDDieVacEnable { get; set; } = false;


        private NotchDir _NotchDir_EQ = NotchDir.Top;
        [DisplayName("Notch 位置(机台)"), Description()]
        public NotchDir NotchDir_EQ
        {
            get { return _NotchDir_EQ; }
            set
            {
                _NotchDir_EQ = value;
                //if (_NotchDir_EQ == NotchDir.Bottom)
                //{
                //    _NotchDir_EQ = NotchDir.Top;
                //};
            }
        }


        //private TR_Selct _LDTRULDSelct = TR_Selct.F0;
        //[DisplayName("载入移载_R1&R2出料角度选择"), Description("顺时针负逆时针正，F0:0度；F90:90; R90:-90; R180:-180")]
        //public TR_Selct LDTR_ULDSelct
        //{
        //    get { return _LDTRULDSelct; }
        //    set
        //    {
        //        _LDTRULDSelct = value;
        //    }
        //}

        //private TR_Selct _ULDTRLDSelct = TR_Selct.F0;
        //[DisplayName("载出移载_R1&R2入料角度选择"), Description("顺时针负逆时针正，F0:0度；F90:90; R90:-90; R180:-180")]
        //public TR_Selct ULDTR_LDSelct
        //{
        //    get { return _ULDTRLDSelct; }
        //    set
        //    {
        //        _ULDTRLDSelct = value;
        //    }
        //}

        //private TR_Selct _ULDTRULDSelct = TR_Selct.F0;
        //[DisplayName("载出移载_R1&R2出料角度选择"), Description("顺时针负逆时针正，F0:0度；F90:90; R90:-90; R180:-180")]
        //public TR_Selct ULDTR_ULDSelct
        //{
        //    get { return _ULDTRULDSelct; }
        //    set
        //    {
        //        _ULDTRULDSelct = value;
        //    }
        //}
        public override string ToString()
        {
            return "...";
        }
    }

    public class PRM_Exc_Rec
    {
        [DisplayName("01.倒膜压力根据产品数量变化"), Description("启用：True,使用每个颗粒倒膜压力(N/pcs);关闭：False,使用倒膜压力设定")]
        public bool ExcPressureByCountEnable { get; set; } = true;

        private double _exchangePressurePcs = 0.2;
        [DisplayName("02.每个颗粒倒膜压力(N/pcs)"), Description("0.01~0.5N/pcs")]
        public double ExchangePressurePcs
        {
            get { return _exchangePressurePcs; }
            set
            {
                _exchangePressurePcs = value;
                if (_exchangePressurePcs < 0)
                {
                    _exchangePressurePcs = 0;
                }

                if (_exchangePressurePcs > 0.5)
                {
                    _exchangePressurePcs = 0.5;
                }
            }
        }

        private double _exchangePressure = 0.05;
        [DisplayName("03.倒膜压力设定(Mpa)"), Description("0~0.5Mpa")]
        public double ExchangePressure
        {
            get { return _exchangePressure; }
            set
            {
                _exchangePressure = value;
                if (_exchangePressure < 0)
                {
                    _exchangePressure = 0;
                }

                if (_exchangePressure > 0.5)
                {
                    _exchangePressure = 0.5;
                }
            }
        }

        private double _exchangetime = 0.1;
        [DisplayName("04.倒膜保压时间设定(Sec)"), Description("0.1~900sec")]
        public double ExchangeTime
        {
            get { return _exchangetime; }
            set
            {
                _exchangetime = value;
                if (_exchangetime < 0.1)
                {
                    _exchangetime = 0.1;
                }

                if (_exchangetime > 900)
                {
                    _exchangetime = 900;
                }
            }
        }
        [DisplayName("05.倒膜Z轴二段速功能"), Description("启用：True,关闭：False")]
        public bool SepratePeelingEnale { get; set; } = true;

        private double _firstPeelingSpeed = 0.2;
        [DisplayName("06.倒膜Z轴一段分离速度设定(mm/s)"), Description("0.5~10mm/s")]
        public double FirstPeelingSpeed
        {
            get { return _firstPeelingSpeed; }
            set
            {
                _firstPeelingSpeed = value;
                if (_firstPeelingSpeed < 0.5)
                {
                    _firstPeelingSpeed = 0.5;
                }

                if (_firstPeelingSpeed > 10)
                {
                    _firstPeelingSpeed = 10;
                }
            }
        }
        private double _firstPeelingDistance = 5;
        [DisplayName("07.倒膜Z轴一段高度设定(mm)"), Description("1~10mm")]
        public double FirstPeelingDistance
        {
            get { return _firstPeelingDistance; }
            set
            {
                _firstPeelingDistance = value;
                if (_firstPeelingDistance < 1)
                {
                    _firstPeelingDistance = 1;
                }

                if (_firstPeelingDistance > 10)
                {
                    _firstPeelingDistance = 10;
                }
            }
        }
        private double _peeling1Waitingtime = 60;
        [DisplayName("08.倒膜Z轴一段分离后等待时间设定(Sec)"), Description("0.1~900sec")]
        public double Peeling1WaitingTime
        {
            get { return _peeling1Waitingtime; }
            set
            {
                _peeling1Waitingtime = value;
                if (_peeling1Waitingtime < 0.1)
                {
                    _peeling1Waitingtime = 0.1;
                }

                if (_peeling1Waitingtime > 900)
                {
                    _peeling1Waitingtime = 900;
                }
            }
        }
        private double _secondPeelingSpeed = 1;
        [DisplayName("09.倒膜Z轴二段分离速度设定(mm/s)"), Description("0.5~50mm/s")]
        public double SecondPeelingSpeed
        {
            get { return _secondPeelingSpeed; }
            set
            {
                _secondPeelingSpeed = value;
                if (_secondPeelingSpeed < 0.5)
                {
                    _secondPeelingSpeed = 0.5;
                }

                if (_secondPeelingSpeed > 50)
                {
                    _secondPeelingSpeed = 50;
                }
            }
        }
        private double _peelingWaitingtime = 120;
        [DisplayName("10.倒膜Z轴二段分离后等待时间设定(Sec)"), Description("0.1~900sec")]
        public double PeelingWaitingTime
        {
            get { return _peelingWaitingtime; }
            set
            {
                _peelingWaitingtime = value;
                if (_peelingWaitingtime < 0.1)
                {
                    _peelingWaitingtime = 0.1;
                }

                if (_peelingWaitingtime > 900)
                {
                    _peelingWaitingtime = 900;
                }
            }
        }
        public override string ToString()
        {
            return "...";
        }
    }
    public class PRM_Laser_Rec
    {
        [DisplayName("01.镭射刻印条件"), Description()]
        [TypeConverter(typeof(PropertiesExpandConverter))]
        public MarkingParameter MarkingParameter { get; set; } = new MarkingParameter();

        [DisplayName("02.激光功率监测"), Description()]
        [TypeConverter(typeof(PropertiesExpandConverter))]
        public LaserPower PowerValue { get; set; } = new LaserPower();


        private int _laserProgramNo = 0;
        [DisplayName("03.程序编号选择"), Description("0~1999")]
        public int LaserProgramNo 
        {
            get { return _laserProgramNo; } 
            set
            {
                _laserProgramNo = value;
                if (_laserProgramNo <0)
                {
                    _laserProgramNo = 0;
                }

                if (_laserProgramNo>1999)
                {
                    _laserProgramNo = 1999;
                }
            }
        }

        [DisplayName("04.信息组编号选择"), Description(""),ReadOnly(true)]
        public uint LaserBlockSel { get; set; } = 1;

        [DisplayName("05.信息组刻印参数"), Description(), ReadOnly(true)]
        [TypeConverter(typeof(PropertiesExpandConverter))]
        public List<BlockInfo> Blocks { get; set; } = new List<BlockInfo>();

        private uint _laserBlockColNum = 1;
        [DisplayName("06.信息组行字符数设定"), Description("每个信息组行字符数")]
        public uint LaserBlockColNum
        {
            get
            {
                return _laserBlockColNum;
            }
            set
            {
                _laserBlockColNum = value;
                if (_laserBlockColNum <= 0)
                {
                    _laserBlockColNum = 1;
                }

                if (_laserBlockColNum > 10)
                {
                    _laserBlockColNum = 10;
                }
            }
        }

        [DisplayName("07.镭射坐标基准"), Description(), ReadOnly(true)]
        [TypeConverter(typeof(PropertiesExpandConverter))]
        public PRM_LaserPos.Laser_Point LaserBase { get; set; } = new PRM_LaserPos.Laser_Point();

        [DisplayName("08.镭射坐标补正"), Description()]
        [TypeConverter(typeof(PropertiesExpandConverter))]
        public PRM_LaserPosOffset LaserPosOffset { get; set; } = new PRM_LaserPosOffset();

        [DisplayName("09.镭射后读码抽检设定"), Description()]
        [TypeConverter(typeof(PropertiesExpandConverter))]
        public LaserInspSpotCheck SpotCheck { get; set; } = new LaserInspSpotCheck();

        public override string ToString()
        {
            return "...";
        }

        public class LaserPower
        {
            private double _baseValue = 0;
            [DisplayName("01.输出功率设定值(W)"), Description("输出功率设定值(W)：0.00-999.99")]
            public double BaseValue
            {
                get
                {
                    return Math.Round(_baseValue,2);
                }
                set
                {
                    _baseValue = value;
                    if (_baseValue <= 0.00)
                    {
                        _baseValue = 0.00;
                    }

                    if (_baseValue > 999.99)
                    {
                        _baseValue = 999.99;
                    }
                }
            }

            private double _rangeValue = 0;
            [DisplayName("02.输出功率监控上下限(±W)"), Description("输出功率设定值(±W)：0.00-1.00")]
            public double RangeValue
            {
                get
                {
                    return Math.Round(_rangeValue,2);
                }
                set
                {
                    _rangeValue = value;
                    if (_rangeValue <= 0.00)
                    {
                        _rangeValue = 0.00;
                    }

                    if (_rangeValue > 1.00)
                    {
                        _rangeValue = 1.00;
                    }
                }
            }
            public override string ToString()
            {
                return "...";
            }
        }

        public class LaserInspSpotCheck
        {
            private uint _spotNum = 1;
            [DisplayName("01.抽检数量(颗)"), Description("抽检数量(颗)")]
            public uint SpotNum
            {
                get
                {
                    return _spotNum;
                }
                set
                {
                    _spotNum = value;
                    if (_spotNum <= 0)
                    {
                        _spotNum = 1;
                    }

                    if (_spotBase > 9999)
                    {
                        _spotBase = 9999;
                    }

                    if (_spotNum > _spotBase)
                    {
                        _spotNum = _spotBase;
                    }
                }
            }

            private uint _spotBase = 1;
            [DisplayName("02.抽检基数(颗)"), Description("抽检基数(颗)")]
            public uint SpotBase
            {
                get
                {
                    return _spotBase;
                }
                set
                {
                    _spotBase = value;
                    if (_spotBase <= 0)
                    {
                        _spotBase = 1;
                    }

                    if (_spotBase > 9999)
                    {
                        _spotBase = 9999;
                    }

                    if (_spotBase < _spotNum)
                    {
                        _spotBase = _spotNum;
                    }

                }
            }
            public override string ToString()
            {
                return "...";
            }
        }
    }
}
